<template>
	<view class="container param-contents">
		<h5 class="param-title">{{ paramTitle }}</h5>
		<!-- 仓控参数查询 -->
		<view v-if="type == 1">
			<view class="bin-card">
				<view class="bin-one" v-for="(one, index) in Number(binNum)" :key="index">
					<view class="bin-border" @click="goStateDetail(index)">{{ index + 1 }}号仓</view>
				</view>
			</view>
		</view>
		<!-- 主控参数查询 -->
		<view v-else-if="type==0">
			<u-cell-group :border="false">
				<u-cell-item title="网络状态:" :arrow="false" :value="NETWORK[masterControl.param1] || masterControl.param1"
					:value-style="{color: comColor(masterControl.param1)}">
				</u-cell-item>
				<u-cell-item title="信号强度:" :arrow="false" :value="masterControl.param2">
				</u-cell-item>
				<u-cell-item title="主平台连接状态:" :arrow="false"
					:value="PLATFORM_CONNECT[masterControl.param3] || masterControl.param3"
					:value-style="{color: comColor(masterControl.param3)}">
				</u-cell-item>
				<u-cell-item title="运维平台连接状态:" :arrow="false"
					:value="PLATFORM_CONNECT[masterControl.param4] || masterControl.param4"
					:value-style="{color: comColor(masterControl.param4)}">
				</u-cell-item>
				<u-cell-item title="ICCID:" :arrow="false" :value="masterControl.param5">
				</u-cell-item>
				<u-cell-item title="整柜禁用状态:" :arrow="false"
					:value="IS_ENABLE[masterControl.param6] ||masterControl.param6"
					:value-style="{color: comColor2(masterControl.param6)}">
				</u-cell-item>
				<u-cell-item title="摄像头是否在线:" :arrow="false"
					:value="IS_ONLINE[masterControl.param7] || masterControl.param7"
					:value-style="{color: comColor(masterControl.param7)}">
				</u-cell-item>
				<u-cell-item title="换电状态:" :arrow="false"
					:value="POWER_CHANGE[masterControl.param8] || masterControl.param8"
					:value-style="{color: comColor(masterControl.param8)}">
				</u-cell-item>
			</u-cell-group>
		</view>
		<!-- 操作按钮 -->
		<view class="operate_btns" v-if="type == 0">
			<u-button type="primary" size="medium" class="set_btn" @click="isRead(0)">查询</u-button>
		</view>
		<!-- 检测单元 -->
		<view v-else-if="type==2">
			<view class="bin-card">
				<view class="bin-one box-one" v-for="(one,index) in comCabinNum" :key="index" :is-shadow="false">
					<view class="bin-border" @click="goStateDetail(index)">检测单元{{index+1}}</view>
				</view>
			</view>
		</view>
		<!-- 柜控电源 -->
		<view v-else-if="type==3">
			<view class="bin-card">
				<view class="bin-one box-one" v-for="(one,index) in comCabinNum" :key="index" :is-shadow="false">
					<view class="bin-border" @click="goStateDetail(index)">柜控电源{{index+1}}</view>
				</view>
			</view>
		</view>
		<!-- 整流电源 -->
		<view v-else-if="type==4">
			<view class="bin-card">
				<view class="bin-one box-one" v-for="(one,index) in comCabinNum*3" :key="index" :is-shadow="false">
					<view class="bin-border" @click="goStateDetail(index)">整流电源{{index+1}}</view>
				</view>
			</view>
		</view>
		<!-- 充电电源 -->
		<view v-else-if="type==5">
			<view class="bin-card">
				<view class="bin-one box-one" v-for="(one,index) in Number(binNum)" :key="index" :is-shadow="false">
					<view class="bin-border" @click="goStateDetail(index)">充电电源{{index+1}}</view>
				</view>
			</view>
		</view>
		<!-- 电池 -->
		<view v-else-if="type==6">
			<view class="bin-card">
				<view class="bin-one" v-for="(one,index) in Number(binNum)" :key="index" :is-shadow="false">
					<view class="bin-border" @click="goStateDetail(index)">电池{{index+1}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		NETWORK,
		PLATFORM_CONNECT,
		IS_ENABLE,
		IS_ONLINE,
		POWER_CHANGE,
	} from "@/common/config.js"
	import statejs from './state.js';
	export default {
		mixins: [statejs],
		data() {
			return {
				type: 0, //参数类型
				paramTitle: "", //参数模块名称
				binNum: 0, //仓个数
				currentIndex: null, //当前仓号
				command: null, //命令字
				deviceInfo: {}, //设备信息
				dgMessage: "", //检测状态提示信息

				masterControl: { //主控状态
					param1: '',
					param2: '',
					param3: '',
					param4: '',
					param5: '',
					param6: '',
					param7: '',
					param8: '',
				},

				NETWORK: NETWORK,
				PLATFORM_CONNECT: PLATFORM_CONNECT,
				IS_ENABLE: IS_ENABLE,
				IS_ONLINE: IS_ONLINE,
				POWER_CHANGE: POWER_CHANGE,
			};
		},
		computed: {
			// 柜控电源数量
			comCabinNum() {
				if (Number(this.binNum) < 24) {
					return 1;
				} else if (Number(this.binNum) >= 24 && Number(this.binNum) < 36) {
					return 2;
				} else {
					return 3;
				}
			},
			comColor() {
				return function(item) {
					if (item == 0) {
						return '#f56c6c';
					} else if (item == 1) {
						return '#19be6b'
					}
				}
			},
			comColor2() {
				return function(item) {
					if (item == 1) {
						return '#f56c6c';
					} else if (item == 0) {
						return '#19be6b'
					}
				}
			},
		},
		onLoad(e) {
			this.deviceInfo = JSON.parse(decodeURIComponent(e.deviceInfo));
			this.type = e.type;
			this.binNum = e.binNum;
			this.detailData();
			// 进入页面，读取一次
			if (this.command == 0) {
				for (let key of Object.keys(this.masterControl)) {
					this.masterControl[key] = "";
				}
				this.doRead();
			}
		},
		methods: {
			goStateDetail(index) {
				uni.navigateTo({
					url: `/pagesA/bluetooth/state/stateDetail?type=${this.type}&binNum=${this.binNum}&index=${index}&deviceInfo=${encodeURIComponent(JSON.stringify(this.deviceInfo))}`
				})
			},
		},
	};
</script>

<style lang="scss" scoped>
	@import "@/static/css/common.scss";
	@import "../index.scss";

	.param-contents {
		padding: 20rpx;
		background: #ffffff;

		.param-one {
			@include flexLayout(center, flex-start);
			border-bottom: 2rpx solid #e5e5e5;
			font-size: 28rpx;
			color: #333333;
			padding: 10rpx 0;

			text {
				width: 220rpx;
				text-align: right;
				margin-right: 20rpx;
			}
		}

		.operate_btns {
			text-align: center;
			margin: 60rpx 0 20rpx;
		}

		.param-title {
			border-left: 8rpx solid #0081ff;
			padding-left: 12rpx;
			border-radius: 8rpx;
			color: #0081ff;
			font-size: 36rpx;
			font-weight: bold;
			margin: 10rpx 0 40rpx;
		}

		.bin_left {
			margin-bottom: 40rpx;
		}
	}
</style>